/**
 * 
 */
package com.ynet.middleground.user.mq.producer;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONArray;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.user.mq.SourceZt;

/**
 * @author songyf
 * @description 中台需要推送的其它业务部分数据
 * @date 2020-10-29 17:57
 */
@EnableBinding({SourceZt.class})
@Component
public class ZtProducer {
    @Autowired
    SourceZt sourceZt;
    
    /**
     * 给渠道推送企业信息修改消息
     *
     * @param jsonArray 推送企业信息修改消息
     */
    public void sendMessagesModifyUserIn(Integer userId,String companyName) {
        Map<String, Object> msgMap = new HashMap<>(3);  
        msgMap.put("time", LocalDateTime.now());
        msgMap.put("userId", userId);
        msgMap.put("companyName", companyName);
        msgMap.put("desc", "企业用户信息发生修改");
        IfpLogger.info("mq", "给渠道推送企业信息修改消息，往 Binding-{} 推送信息-{}", SourceZt.ENTERPRISE_BASIC_MODIFY, msgMap);
        Map<String, Object> headers = new HashMap<>(1);
        // tags 标签对应 yml 配置文件
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(msgMap, messageHeaders);
        this.sourceZt.UserModifyNotice().send(message);
    }
    
    /**
     * 给渠道推送用户密码变更消息
     *
     * @param jsonArray 给渠道推送用户密码变更消息
     */
    public void sendMessagesModifyUserPasswordIn(Integer userId,String userName) {
        Map<String, Object> msgMap = new HashMap<>(3);  
        msgMap.put("time", LocalDateTime.now());  
        msgMap.put("userId", userId);
        msgMap.put("userName", userName);
        msgMap.put("desc", "用户密码发生变更，其它渠道也进行同步修改");
        IfpLogger.info("mq", "给渠道推送用户密码变更消息，往 Binding-{} 推送信息-{}", SourceZt.USER_PASSWORD_MODIFY, msgMap);
        Map<String, Object> headers = new HashMap<>(1);
        // tags 标签对应 yml 配置文件
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(msgMap, messageHeaders);
        this.sourceZt.UserPasswordModifyNotice().send(message);
    }
}
